﻿@model IEnumerable<DefeatEpidemic.Models.Application>

<div class="layui-row">
    <span class="layui-breadcrumb">
        <a href="~/home/index">首页</a>
        <a href="~/applications/Index">申请管理</a>
        <a>
            <cite>申请列表</cite>
        </a>
    </span>
    <a class="layui-btn layui-btn-xs" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon layui-icon-refresh-1" style="line-height:25px;font-size: 10px"></i>
    </a>
</div>
<hr />

<p>
    <div class="layui-form-item">
        <label class="layui-form-label">检索</label>
        <div class="layui-input-inline">
            <input type="text" id="applicant" class="layui-input" placeholder="请输入申请人" />
        </div>
        <div class="layui-input-inline">
            <input type="text" id="start" class="layui-input" placeholder="请选择开始日期" />
        </div>
        <div class="layui-input-inline">
            <input type="text" id="end" class="layui-input" placeholder="请选择结束日期" />
        </div>
        <a href="javascript:;" id="btn_search" class="layui-btn layui-btn-normal">检索</a>
        <a id="export" class="layui-btn">导出</a>
    </div>
</p>
<table class="layui-table" id="table"></table>
<script type="text/html" id="operationTpl">
    <a onclick="check(1, '{{ d.id }}')" class="layui-btn layui-btn-normal">允许</a>
    <a onclick="check(-1, '{{ d.id }}')" class="layui-btn layui-btn-danger">驳回</a>
</script>
<script type="text/html" id="statusTpl">
    {{# if(d.status==0){}}
    <span style="color:#FFB800;">未审核</span>
    {{# } }}
    {{# if(d.status==1){}}
    <span style="color:#5FB878;">出申请通过</span>
    {{# } }}
    {{# if(d.status==2){}}
    <span style="color:#1E9FFF;">进申请通过</span>
    {{# } }}
    {{# if(d.status==-1){}}
    <span style="color:#FF5722;">未通过</span>
    {{# } }}
</script>

<script>
    var token = $('@Html.AntiForgeryToken()').val();
    var query = getQueryString("member_id");
    var data = {};
    if (query) {
        data.member_id = query;
    }
    var params = {
        url: '@Url.Action("GetList")',
        elem: '#table',
        where: data,
        size: 'lg',
        page: true,
        cols: [ //表头            
            { title: '序号', templet: "#indexTpl",width:80 }
            , { field: 'applicant', title: '申请人',width:100 }
            , { field: 'from', title: '从哪来' }
            , { field: 'to', title: '到哪去' }
            , { field: 'connect', title: '联系方式',width:150 }            
            , { field: 'carNumber', title: '车牌号' }
            , { field: 'reason', title: '原因' }
            , { field: 'selfTemp', title: '自测体温',width:100 }
            , { field: 'measuredTemp', title: '实测体温',width:100 }
            , { title: '审批状态', templet: '#statusTpl',width:100 }            
            , { field: 'created_at', title: '申请时间' }
            , { title: '操作', templet: '#operationTpl',width:200 }
        ],
        height: 630
    }
    getTable(params);
    //检索
    $("#btn_search").click(function () {
        var applicant = $("#applicant").val();
        var start = $("#start").val();
        var end = $("#end").val();

        var where = {
            'applicant': applicant,
            'start': start,
            'end':end
        };
        params.where = where;
        getTable(params);
    })

    var export_flag = true;
    var time = 10;
    //导出
    $("#export").click(function () {        
        if (export_flag) {
            var applicant = $("#applicant").val();
            var start = $("#start").val();
            var end = $("#end").val();
            var form = $("<form style='display:none'>");
            var params1 = $('<input type="text" name="applicant" />');
            var params2 = $('<input type="text" name="start" />');
            var params3 = $('<input type="text" name="end" />');
            params1.attr('value', applicant);
            params2.attr('value', start);
            params3.attr('value', end);
            form.attr("style", "disblay:none");
            form.attr("target", "");
            form.attr("method", "post");
            form.attr("action", "@Url.Action("Export")");
            form.append(params1);
            form.append(params2);
            form.append(params3);
            $("body").append(form);//将表单放置在web中
            form.submit();
            export_flag = false;            
        }
        else {
            layer.msg("如果10秒后仍无反应请尝试再次点击");
        }
        setTimeout(function () {//这里的设置其实不太合理，应该是通过Ajax提交生成excel的请求，在后台生成文件后，返回下载链接，时间关系，先这么简单处理了
            export_flag=true;
        }, 10000);
    })

    function check(status, apply_id) {
        UpdateItem("@Url.Action("Check")", { "status": status, "apply_id": apply_id, "__RequestVerificationToken": token }, "确定要审核该条申请吗");
    }

    layui.use('laydate', function () {
        var laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '#start' //指定元素
            , type: 'datetime'
        });
        laydate.render({
            elem: '#end' //指定元素
            , type: 'datetime'
        });
    });
</script>
